Skip to content

perf(diff): parallel copy, hashing and cleanup, and --format json - #2021

Open
italo-kalil-cesar wants to merge 2 commits into
mendixlabs:mainfrom
italo-kalil-cesar:pr/diff-parallel
Open

italo-kalil-cesar wants to merge 2 commits into
mendixlabs:mainfrom
italo-kalil-cesar:pr/diff-parallel

Conversation

@italo-kalil-cesar

@italo-kalil-cesar italo-kalil-cesar commented Dec 2, 2026 •

Copy link
Copy Markdown

Part of #2014

Marked ready for review. The issue asks the maintainers whether a faster diff is in scope and which JSON spelling they prefer.

What was wrong

mxcli diff spent most of its time copying the project to the scratch folder one file at a time, hashing the files next to the model one at a time, and removing the scratch folder one file at a time (about 18 s of 26 s on a project of about 3 thousand units, Windows). A tool also had to parse the text of the diff to know the result.

What changes

Two commits, one thing each:

  1. scriptdiff: parallel copy, hashing and cleanup; skip packages/; timing: regular files are copied by a pool of workers, the files next to the model are hashed by a pool, the first three levels of the scratch folder are removed in parallel. packages/ (deployment packages exported by Studio Pro, never read or written by exec) joins the directories the copy leaves out. MXCLI_DIFF_TIMING=1 prints each stage's time to stderr. Docs: diff page and command help; CHANGELOG.
  2. diff: --format json prints the report as one JSON document: refused, preflight, execError, failures, units, documents, files, summary. Docs: JSON output section, flag help, the --json refusal hint; CHANGELOG.

Question for the maintainers: other commands expose JSON through the global --json flag (diff refused it so far, with a hint). This adds --format json instead, as lint and report do. If you prefer --json, the report writer is the same and only the flag wiring changes.

Measured

Project of about 3 thousand units (about 430 MB outside the skipped directories), Windows: a one-statement script 30.8 s -> about 13 s, same report on the scripts tried. That is the sum of the three parallel changes and the skipped directory; they were not measured one by one.

Tests

parallel_test.go (copy skips the build directories and copies every file; parallel removal; SHA-256 file hash) and json_test.go (modified document and file; refused script reports writesNothing and empty lists). Smoke test of mxcli diff --format json on the PedApp fixture: an added enumeration is reported as expected, and a refused script prints the refusal with writesNothing: true.

  • go test ./mdl/scriptdiff: ok except TestDiffFollowsAConnectToTheProjectOntoTheCopy, which fails on Windows at TempDir cleanup (open file) and fails the same on main.

Run locally

Run on Windows without make; the equivalents were run by hand:

  • go build ./...: clean
  • go vet on the touched packages: clean
  • gofmt -l on the touched files: empty
  • go test -timeout ... on the touched packages: see Tests
  • make check-test-timeouts, make check-findings: not run (bash and make are not available here); no Makefile or findings file is touched

Studio Pro validation

Not run. diff writes nothing to the project.

Agentic testing

Not run.

italo-kalil-cesar and others added 2 commits December 1, 2026 22:53
mxcli diff spent most of its time (about 18 s of 26 s on a 3,100-unit project,
Windows) copying the project one file at a time, then hashing the files next to
the model and removing the scratch folder one file at a time.

- copyProject: regular files are copied by a pool of workers (directories and
  symlinks are still created in walk order).
- TakeSnapshot: the files next to the model are hashed by a pool of workers.
- Scratch.Close: the first three levels of the scratch folder are removed in
  parallel.
- packages/ (deployment packages exported by Studio Pro) joins the skipped
  directories: build output that exec never reads or writes.
- MXCLI_DIFF_TIMING=1 prints the time of each stage of a diff to stderr.

Measured on one project (3,138 units, ~430 MB outside the skipped directories):
diff of a one-statement script 30.8 s -> about 13 s; same output as before on
the scripts tried.

Tests: the copy skips the build directories and copies every file, the parallel
removal removes the tree, the file hash is SHA-256.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
For a tool that has to decide on the result of a diff without parsing the text:
refused, preflight, execError, failures, units, documents, files and summary.
A script exec would refuse reports refused and summary.writesNothing.

Docs: the diff page gains a JSON output section, the flag help and the --json
refusal hint name the format, and CHANGELOG has the entry.

Tests: a modified document and file are reported with the right kinds and
summary; a refused script has writesNothing and empty (not null) lists.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant